home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 002a / be310.zip / FACT.CHS < prev    next >
Text File  |  1993-06-01  |  911b  |  29 lines

  1. /* CHESS FUNCTION(S): FACT.CHS -- standalone Chess program
  2. /*              DATE:
  3. /*            AUTHOR:
  4. /*
  5. /*       DESCRIPTION: this does a factorial generation -- useful as an 
  6. /* example of recursion
  7. {
  8.    char temp[30];
  9.    int i;
  10.    temp[0]=0;
  11.    if((get_str(temp,"Find factorial of What number (1-12)?",2)%256)!=27){
  12.       /* if the user didn't press escape
  13.       i=atoi(temp);       /* convert to an integer
  14.       i=do_fact(i);       /* find its factorial
  15.       msg("%s factorial is %ld",temp,i); /* print it out
  16.       getkey();           /* wait for a keypress
  17.    }
  18. }
  19. do_fact           /* this function is a recursive one
  20. int n;            /* single parameter
  21. {
  22.    if((n<1)||(n>12)) /* if illegal, return 0
  23.       return(0);
  24.    else if(n==1)  /* if we are done with recursive call
  25.       return(1);
  26.    else           /* else, recurse another level
  27.       return(do_fact(n-1)*n);
  28. }
  29.